<template>
  <div class="user-container">
    <!-- 用户基本信息面板 -->
    <div class="user-card">
      <!-- 用户头像、姓名 -->
      <van-cell>
        <!-- 使用 title 插槽来自定义标题 -->
        <template #icon>
          <img :src="userInfo.photo" alt="" class="avatar" />
        </template>
        <template #title>
          <span class="username">{{ userInfo.name }}</span>
        </template>
        <template #label>
          <van-tag color="#fff" text-color="#007bff">申请认证</van-tag>
        </template>
      </van-cell>
      <!-- 动态、关注、粉丝 -->
      <div class="user-data">
        <div class="user-data-item">
          <span>{{ userInfo.art_count }}</span>
          <span>动态</span>
        </div>
        <div class="user-data-item" @click="checkFollows">
          <span>{{ userInfo.follow_count }}</span>
          <span>关注</span>
        </div>
        <div class="user-data-item">
          <span>{{ userInfo.fans_count }}</span>
          <span>粉丝</span>
        </div>
      </div>
    </div>
    <!-- 关注 粉丝  动态的点击 -->
    <van-overlay v-show="followShow">
      <div class="wrapper" @click.stop>
        <div class="block">
          <ul>
            <li v-for="(index,obj) in followItem" :key="obj.id">
              {{obj.name}}
            </li>
          </ul>
          <button class="cancel" @click = "followShow=false">取消</button>
        </div>
        
      </div>
    </van-overlay>

    <!-- 操作面板 -->
    <van-cell-group class="action-card">
      <van-cell icon="edit" title="编辑资料" is-link @click="EditUser" />
      <!-- <van-cell icon="chat-o" title="小思同学" is-link /> -->
      <van-cell icon="warning-o" title="退出登录" is-link @click="exit" />
    </van-cell-group>
  </div>
</template>

<script>
import { userInfoAPI ,checkFollow} from "../../api";
import { Dialog } from "vant";
import { removeToken } from "../../utils/token";
export default {
  data() {
    return {
      userInfo: [],
      followShow:false, //控制关注的弹出框
      followItem:[],//存储关注人的信息
    };
  },
  async activated() {
    await this.getUserInfo();
  },
  methods: {
    //获取用户信息
    async getUserInfo() {
      const res = await userInfoAPI();
      // console.log(res);
      this.userInfo = res.data.data;
    },
    exit() {
      Dialog.confirm({
        title: "退出",
        message: "你确定要退出嘛？",
      })
        .then(() => {
          // on confirm
          //   确认退出的话,要跳转到登录页面,并且清除token
          //   console.log(111);
          // this.removeToken()
          removeToken(), this.$router.replace("/login");
        })
        .catch(() => {
          console.log(222);
          // on cancel
        });
    },
    EditUser() {
      this.$router.push({
        path: "/userEdit",
      });
    },
    async checkFollows() {
      
      const res = await checkFollow({
        pages:1,
        per_pages:10
      })
      this.followShow = true
      // console.log(res)
      this.followItem = res.data.data.results
      console.log(this.followItem);
    },
  },
};
</script>

<style scoped lang="less">
.user-container {
  .user-card {
    background-color: #007bff;
    color: white;
    padding-top: 20px;
    .van-cell {
      background: #007bff;
      color: white;
      &::after {
        display: none;
      }
      .avatar {
        width: 60px;
        height: 60px;
        background-color: #fff;
        border-radius: 50%;
        margin-right: 10px;
      }
      .username {
        font-size: 14px;
        font-weight: bold;
      }
    }
  }
  .user-data {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    font-size: 14px;
    padding: 30px 0;
    .user-data-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 33.33%;
    }
  }
}
.wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .block {
    width: 8rem;
    height: 8rem;
    background-color: #fff;
    .cancel {
      width: 100%;
      height: 1.3rem;
      margin-top: 70%;
      border: none;
      text-align: center;
    }
    li {
      width: 100%;
      height: 1.5rem;
      background-color: #f3f3f3;
    }
  }
</style>
